<!DOCTYPE html>
<html>
<head>
    <title>ClassDiaryTable</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" href="../../css/font-awesome.min.css">
    <link rel="stylesheet" href="../../plugins/jqgrid/ui.jqgrid-bootstrap.css">
    <link rel="stylesheet" href="../../plugins/ztree/css/metroStyle/metroStyle.css">
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css">
    <link rel="stylesheet" href="../../css/main.css">
    <link rel="stylesheet" href="../../plugins/treegrid/jquery.treegrid.css">

    <script src="../../libs/jquery.min.js"></script>
    <script src="../../plugins/layer/layer.js"></script>
    <script src="../../libs/bootstrap.min.js"></script>
    <script src="../../libs/vue.min.js"></script>
    <script src="../../libs/validator.min.js"></script>
    <script src="../../plugins/jqgrid/grid.locale-cn.js"></script>
    <script src="../../plugins/jqgrid/jquery.jqGrid.min.js"></script>
    <script src="../../plugins/ztree/jquery.ztree.all.min.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../libs/jquery.validate.js"></script>
    <script src="../../libs/validate-methods.js"></script>
    <script src="../../libs/messages_zh.js"></script>
    <script src="../../js/setdate.js"></script>
    <script src="../../libs/My97DatePicker/4.8/WdatePicker.js"></script>
</head>
<body>
<br>
<div id="rrapp" v-cloak>

    <div v-show="showList">
        <div class="search-container">
            <div class="select-container">
                <input type="text" class="mySelect" v-model="q.key" @keyup.enter="query" placeholder="教师名字/课程名称/班级名称">
            <!--<div class="form-group col-sm-2">-->
                <!--<select  class="form-control" id="College">-->
                <!--</select>-->
            <!--</div>-->
        </div>
            <div class="select-container">
                <input type="text" class="mySelect" onfocus="WdatePicker()" id="startDate" name="startDate" placeholder="开始时间"/>
            </div>
            <div class="select-container">
                <input type="text" class="mySelect" onfocus="WdatePicker()" id="endDate" name="endDate"  placeholder="结束时间"/>
            </div>

            <div  class="btn-container">
                <a class="btn-thin" @click="query">查询</a>
            </div>
            <div class="btn-container">
                <span  class="normal-btn normal-color" onclick="setDate('1')">今日</span>
                <span  class="normal-btn normal-color" onclick="setDate('2')">本周</span>
                <span  class="normal-btn normal-color" onclick="setDate('3')">本月</span>
            </div>

            <div  class="btn-container">
                <a class="btn-thin" id="exportExcel">导出</a>
            </div>
        </div>
        <table id="jqGrid"></table >
        <div id="jqGridPager"></div>
    </div>

    <div v-show="!showList" class="panel panel-default">
        <div class="panel-heading">{{title}}</div>
        <form class="form-horizontal">
            <div class="form-group">
                <div class="col-sm-2 control-label">考评时间</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="ClassDiary.diaryPostTime" placeholder="考评时间"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">教师姓名</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="ClassDiary.courseTeacherName" placeholder="教师姓名" @focus="changeTime()"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">课程名称</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="ClassDiary.courseName" placeholder="课程名称" @focus="changeTime()"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">到达时间</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="ClassDiary.arriveTime" placeholder="到达时间"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">离开时间</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="ClassDiary.leaveTime" placeholder="离开时间"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">教授时长</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="ClassDiary.teachLength" placeholder="教授时长"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" class="btn btn-primary" @click="saveOrUpdate" value="确定"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="reload" value="返回"/>
            </div>
        </form>
    </div>
</div>

<script>
    $(function () {
        $("#jqGrid").jqGrid({
            url: baseURL + 'ClassDiaryTable/SelectOfMyCollege',
            datatype: "json",
            colModel: [
                { label: '日期', name: 'diaryPostTime',index:'diary_post_time', width: 35,key: true, sortable:false },
                // { label: '学年', name: 'courseAcademicYear',index:'course_academic_year', width: 40 },
                // { label: '学期', name: 'courseAcademicTerm',index:'course_academic_term', width: 40 },
                // { label: '教学周', name: 'courseWhichWeek',index:'course_which_week', width: 40 },
                // { label: '星期', name: 'courseWhichDay',index:'course_which_day', width: 40 },

                { label: '教师姓名', name: 'courseTeacherName',index:'course_teacher_name', width: 30, sortable:false },
                { label: '工号', name: 'teacherId',index:'course_teacher_name', width: 40, sortable:false },
                { label: '所属院系', name: 'teacherCollege',index:'teacher_college', width: 35 , sortable:false},
                { label: '授课名称', name: 'courseName', index:'course_name',width: 50, sortable:false },
                { label: '节次', name: 'courseWhichIndex',index:'course_which_index', width: 30, sortable:false },

                { label: '授课班级', name: 'className', index:'class_name',width: 50 , sortable:false},
                { label: '到达时间', name: 'arriveTime',index:'arrive_time', width: 35, sortable:false },
                { label: '离开时间', name: 'leaveTime',index:'leave_time', width: 35 , sortable:false},
                { label: '教授时长', name: 'teachLength', index:'teach_length',width: 40, sortable:false },
                { label: '出勤', name: 'isAttendanceState',index:'leave_time', width: 40, sortable:false },
                { label: '布置作业', name: 'isHomeworkState',index:'leave_time', width: 40, sortable:false },
                { label: '考勤', name: 'isAttcheckState',index:'leave_time', width: 40, sortable:false },
                { label: '是否相符', name: 'isMatchContent',index:'leave_time', width: 40, sortable:false },
                { label: '授课类型', name: 'teachingTypeStr',index:'leave_time', width: 40, sortable:false },
                { label: '授课内容', name: '', width: 30, sortable: false, formatter: function(value, options, row){

                        var r='<a class="table-btn1 detail-btn" onclick="showTeachContentAfter(\''+row.teachContentBefore+'\',\''+row.teachContentAfter+'\')">&nbsp;详情</a>'

                        return r;
                    }}

            ],
            viewrecords: true,
            height:'100%',
            rowNum: 10,
            rowList : [10,30,50],
            rownumbers: true,
            rownumWidth: 25,
            autowidth:true,
            multiselect: false,
            pager: "#jqGridPager",
            jsonReader : {
                root: "page.list",
                page: "page.currPage",
                total: "page.totalPage",
                records: "page.totalCount"
            },
            prmNames : {
                page:"page",
                rows:"limit",
                order: "order"
            },
            gridComplete:function(){
                //隐藏grid底部滚动条
                $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
            },
            ondblClickRow:function(rowid){
                var rowData = $("#jqGrid").jqGrid('getRowData',rowid);
                var rowName =$("#jqGrid").jqGrid('getGridParam','colNames');
                var s="";
                var i=2;
                for(var key in rowData){
                    s=s+rowName[i++]+':'+rowData[key]+'<br> ';
                }
                // alert(s);
            }
        });
        $("#exportExcel").attr('href',baseURL+'ClassDiaryTable/export?token='+token);
        // $.ajax({
        //     url: baseURL + "/college/getAllcollege",
        //     data: {},
        //     success: function (r) {
        //         $("#College").append("<option value=''>请选择</option>");
        //         for (i = 0; i < r.list.length; i++) {
        //             var tname = r.list[i].collegeName;
        //             var tid = r.list[i].collegeName;
        //             $("#College").append("<option value='" + tid + "'>" + tname + "</option>");
        //         }
        //     }
        // });
    });
    function  showTeachContentAfter(teachContentBefore,teachContentAfter) {
        if(teachContentBefore==null)
        {
            teachContentBefore=""
        }
        alert("授课内容：<br>    "+teachContentBefore+"<br>教学内容：<br>    "+teachContentAfter);

    }
    function query(){
        vm.query()
    }
    var vm = new Vue({
        el:'#rrapp',
        data:{
            q:{
                key: null,
                startDate:null,
                endDate:null
            },
            showList: true,
            title: null,
            ClassDiary: {},
            diaryPostTime: null,
            term: {}
        },
        methods: {
            query: function () {
                $("#exportExcel").attr('href',baseURL+'ClassDiaryTable/export?token='+token+"&teacherName="+vm.q.key);
                vm.reload();
            },
            add: function(){
                vm.showList = false;
                vm.title = "新增";
                vm.ClassDiary = {};
            },
            update: function () {
                var id = getSelectedRow();
                if(id == null){
                    return ;
                }
                $.get(baseURL + "ClassDiaryTable/Info/"+id, function(r){
                    vm.showList = false;
                    vm.title = "修改";
                    vm.ClassDiary = r.ClassDiary;
                    vm.diaryPostTime = r.ClassDiary.diaryPostTime;
                });
            },
            del: function () {
                var ids = getSelectedRows();
                if(ids == null){
                    return ;
                }
                confirm('确定要删除选中的记录？', function(){
                    $.ajax({
                        type: "POST",
                        url: baseURL + "ClassDiary/Delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                alert('操作成功', function(){
                                    vm.reload();
                                });
                            }else{
                                alert(r.msg);
                            }
                        }
                    });
                });
            },
            saveOrUpdate: function () {
                if(vm.validator()){
                    return ;
                }

                var url = vm.ClassDiary.diaryPostTime == vm.diaryPostTime ? "ClassDiaryTable/Update" : "ClassDiaryTable/Insert";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.ClassDiary),
                    success: function(r){
                        if(r.code === 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            },
            reload: function () {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam','page');
                $("#jqGrid").jqGrid('setGridParam',{
                    postData:{ 'teacherName': vm.q.key,
                        'startDate': $("#startDate").val(),
                        'endDate': $("#endDate").val(),
                        'profession':$("#Profession").val(),
                        'class': $("#Class").val()
                    },
                    page:page
                }).trigger("reloadGrid");
            },
            validator: function () {
                if(isBlank(vm.ClassDiary.diaryPostTime)){
                    alert("考评时间不能为空");
                    return true;
                }
                if(isBlank(vm.ClassDiary.courseTeacherName)){
                    alert("教师姓名不能为空");
                    return true;
                }
                if(isBlank(vm.ClassDiary.courseName)){
                    alert("课程名称不能为空");
                    return true;
                }
                if(isBlank(vm.ClassDiary.arriveTime)){
                    alert("到达时间不能为空");
                    return true;
                }
                if(isBlank(vm.ClassDiary.leaveTime)){
                    alert("离开时间不能为空");
                    return true;
                }
                if(isBlank(vm.ClassDiary.teachLength)){
                    alert("教授时长不能为空");
                    return true;
                }
            }
        }
    });

</script>
</body>
</html>